1 module hip.api.input.binding;
2 
3 version(DirectCall) { public import hip.event.api; }
4 else version(ScriptAPI)
5 {
6     void initInput()
7     {
8         import hip.api.internal;
9         import hip.api.console;
10         loadClassFunctionPointers!HipInputBinding;
11         enum InputMapClass = "HipInputMap";
12         mixin(loadSymbolsFromExportD!(InputMapClass,
13             parseInputMap_Mem
14         ));
15         log("HipengineAPI: Initialized Input");
16     }
17 
18     public import hip.api.input.button;
19     public import hip.api.input.gamepad;
20     public import hip.api.input.mouse;
21     public import hip.api.input.inputmap;
22     public import hip.api.input.keyboard;
23     public import hip.api.renderer.viewport:Viewport;
24     import hip.api.internal;
25 
26     class HipInputBinding
27     {
28         extern(System) __gshared
29         {
30             bool function(char key, uint id = 0) isKeyPressed;
31             bool function(char key, uint id = 0) isKeyJustPressed;
32             bool function(char key, uint id = 0) isKeyJustReleased;
33             float function(char key, uint id = 0) getKeyDownTime;
34             float function(char key, uint id = 0) getKeyUpTime;
35 
36             //Mouse/Touch functions
37             ubyte function(HipMouseButton btn = HipMouseButton.any, uint id = 0) getMulticlickCount;
38             bool function(HipMouseButton btn = HipMouseButton.any, uint id = 0) isDoubleClicked;
39             bool function(HipMouseButton btn = HipMouseButton.any, uint id = 0) isMouseButtonPressed;
40             bool function(HipMouseButton btn = HipMouseButton.any, uint id = 0) isMouseButtonJustPressed;
41             bool function(HipMouseButton btn = HipMouseButton.any, uint id = 0) isMouseButtonJustReleased;
42 
43             ///Gets Raw touch/mouse position
44             float[2] function(uint id = 0) getTouchPosition;
45             ///Gets normallized to the window touch/mouse position
46             float[2] function(uint id = 0) getNormallizedTouchPosition;
47             ///Gets touch position in world transform. The world transform can both be based in Viewport argument, if none is passed, it is based on the currently active viewport
48             float[2] function(uint id = 0, Viewport vp = null) getWorldTouchPosition;
49             float[2] function(uint id=0) getTouchDeltaPosition;
50             float[3] function(uint id=0) getScroll;
51             //Gamepad Functions
52             ubyte function() getGamepadCount;
53             AHipGamepad function(ubyte id = 0) getGamepad;
54             float[3] function(HipGamepadAnalogs analog, ubyte id = 0) getAnalog;
55             bool function(HipGamepadButton btn, ubyte id = 0) isGamepadButtonPressed;
56             bool function(HipGamepadButton btn, ubyte id = 0) isGamepadButtonJustPressed;
57             bool function(HipGamepadButton btn, ubyte id = 0) isGamepadButtonJustReleased;
58 
59 
60             bool function(scope HipGamepadButton[] btn, ubyte id = 0) areGamepadButtonsPressed;
61             bool function(scope HipGamepadButton[] btn, ubyte id = 0) areGamepadButtonsJustPressed;
62             bool function(scope HipGamepadButton[] btn, ubyte id = 0) areGamepadButtonsJustReleased;
63             
64             bool function(float vibrationPower, float time, ubyte id = 0) setGamepadVibrating;
65             float function(ubyte id = 0) getGamepadBatteryStatus;
66             bool function(ubyte id = 0) isGamepadWireless;
67 
68             const(HipButton)* function(HipKey key, HipInputAction action,
69             HipButtonType type = HipButtonType.down,
70             AutoRemove remove = AutoRemove.no) addKeyboardListener;
71 
72             const(HipButton)* function (HipMouseButton btn, HipInputAction action,
73             HipButtonType type = HipButtonType.down,
74             AutoRemove remove = AutoRemove.no) addTouchListener;
75 
76             const(ScrollListener)* function (HipScrollAction onScoll,
77             AutoRemove remove = AutoRemove.no) addScrollListener;
78 
79             const(TouchMoveListener)* function(HipTouchMoveAction onMove,
80             AutoRemove remove = AutoRemove.no) addTouchMoveListener;
81 
82             bool function(const(HipButton)* button) removeKeyboardListener;
83             bool function(const(HipButton)* btn) removeTouchListener;
84             bool function(const(ScrollListener)*) removeScrollListener;
85             bool function(const(TouchMoveListener)*) removeTouchMoveListener;
86         }
87     }
88 
89     mixin ExpandClassFunctionPointers!HipInputBinding;
90     alias addMouseListener = addTouchListener;
91     alias isTouchPressed = isMouseButtonPressed;
92     alias isTouchJustPressed = isMouseButtonJustPressed;
93     alias isTouchJustReleased = isMouseButtonJustReleased;
94 }
95 
96 version(none) //Code suggestion
97 {
98     bool function(char key, uint id = 0) isKeyPressed;
99     bool function(char key, uint id = 0) isKeyJustPressed;
100     bool function(char key, uint id = 0) isKeyJustReleased;
101     float function(char key, uint id = 0) getKeyDownTime;
102     float function(char key, uint id = 0) getKeyUpTime;
103 
104     //Mouse/Touch functions
105     ubyte function(HipMouseButton btn = HipMouseButton.any, uint id = 0) getMulticlickCount;
106     bool function(HipMouseButton btn = HipMouseButton.any, uint id = 0) isDoubleClicked;
107     bool function(HipMouseButton btn = HipMouseButton.any, uint id = 0) isMouseButtonPressed;
108     bool function(HipMouseButton btn = HipMouseButton.any, uint id = 0) isMouseButtonJustPressed;
109     bool function(HipMouseButton btn = HipMouseButton.any, uint id = 0) isMouseButtonJustReleased;
110 
111     ///Gets Raw touch/mouse position
112     float[2] function(uint id = 0) getTouchPosition;
113     ///Gets normallized to the window touch/mouse position
114     float[2] function(uint id = 0) getNormallizedTouchPosition;
115     ///Gets touch position in world transform. The world transform can both be based in Viewport argument, if none is passed, it is based on the currently active viewport
116     float[2] function(uint id = 0, Viewport vp = null) getWorldTouchPosition;
117     float[2] function(uint id=0) getTouchDeltaPosition;
118     float[3] function(uint id=0) getScroll;
119     //Gamepad Functions
120     ubyte function() getGamepadCount;
121     AHipGamepad function(ubyte id = 0) getGamepad;
122     float[3] function(HipGamepadAnalogs analog, ubyte id = 0) getAnalog;
123     bool function(HipGamepadButton btn, ubyte id = 0) isGamepadButtonPressed;
124     bool function(HipGamepadButton btn, ubyte id = 0) isGamepadButtonJustPressed;
125     bool function(HipGamepadButton btn, ubyte id = 0) isGamepadButtonJustReleased;
126 
127 
128     bool function(scope HipGamepadButton[] btn, ubyte id = 0) areGamepadButtonsPressed;
129     bool function(scope HipGamepadButton[] btn, ubyte id = 0) areGamepadButtonsJustPressed;
130     bool function(scope HipGamepadButton[] btn, ubyte id = 0) areGamepadButtonsJustReleased;
131     
132     bool function(float vibrationPower, float time, ubyte id = 0) setGamepadVibrating;
133     float function(ubyte id = 0) getGamepadBatteryStatus;
134     bool function(ubyte id = 0) isGamepadWireless;
135 
136     const(HipButton)* function(HipKey key, HipInputAction action,
137     HipButtonType type = HipButtonType.down,
138     AutoRemove remove = AutoRemove.no) addKeyboardListener;
139 
140     const(HipButton)* function (HipMouseButton btn, HipInputAction action,
141     HipButtonType type = HipButtonType.down,
142     AutoRemove remove = AutoRemove.no) addTouchListener;
143 
144 
145     const(ScrollListener)* function (HipScrollAction onScoll,
146     AutoRemove remove = AutoRemove.no) addScrollListener;
147 
148     const(TouchMoveListener)* function(HipTouchMoveAction onMove,
149     AutoRemove remove = AutoRemove.no) addTouchMoveListener;
150 
151     bool function(const(HipButton)* button) removeKeyboardListener;
152     bool function(const(HipButton)* btn) removeTouchListener;
153     bool function(const(ScrollListener)*) removeScrollListener;
154     bool function(const(TouchMoveListener)*) removeTouchMoveListener;
155 }